Skip to main content

All Questions

2votes
3answers
199views

Is it still "feature envy" if the state to make decision or the action to take after asking the state involves other classes to participate?

According to https://softwareengineering.stackexchange.com/a/212130/432039, if a class asks another class for the state, and then call methods of that class, it is called "feature envy", eg: ...
wcminipgasker2023's user avatar
4votes
2answers
520views

How to avoid duplication in a for loop when "initialization step" is identical to "update step"?

I often find a situation where I need to write duplicate codes in a for loop, where the "init step" to identical to the "update step": // duplicate `next()` for (let x = next(); p(x); x = next()) { ...
Chiawen's user avatar
6votes
4answers
10kviews

Refactoring many else if, else if, else if, etc. statements

I'm trying to parse readable data from PDFs and I keep ending up writing code like the following: if (IsDob(line)) { dob = ParseDob(line); } else if (IsGender(line)) { gender = ParseGender(...
Levi H's user avatar
11votes
4answers
827views

Good code style to introduce data checks everywhere?

I have a project that is sufficiently large in size that I can't keep every aspect in my head any more. I'm dealing with a number of classes and functions in it, and I'm passing data around. With ...
user7088941's user avatar
2votes
2answers
213views

Should one create shareable private class member or keep variable in method scope to pass it as a second method argument?

Recently I had to refactor some legacy code. As in most cases, I had to split big parts of code into smaller, cleaner and readable functions. I ended with many functions, that had multiple, weird ...
helvy91's user avatar
0votes
5answers
230views

What should I consider when adding a condition to an existing function? [closed]

I often find that I need to add new conditional feature to code that already exists. This requires me to keep the existing functionality while tacking on something new. I've tried each of the ...
Bindelstif's user avatar
32votes
10answers
8kviews

Is "Parent x=new Child();" instead of "Child x=new Child();" a bad practice if we can use the latter one?

For example,I had seen some codes that create a fragment like this: Fragment myFragment=new MyFragment(); which declares a variable as Fragment instead of MyFragment , which MyFragment is a child ...
ggrr's user avatar
  • 5,863
1vote
1answer
155views

Refactoring List abstraction - C

Below is the working List abstraction design, List is a generic abstraction holding any type. Below is the code directory structure. Currently symbol table(ST) and file api fileIO is using List ...
overexchange's user avatar
2votes
1answer
186views

RefactorException: Good idea or bad idea?

When I'm doing large scale refactors I'm often commenting out the contents of methods and using NotImplementedExceptions for stuff that I still need to refactor. Problem is that this is interfering ...
Dirk Boer's user avatar
0votes
3answers
1kviews

Eliminate duplicate code in nested IFs without creating a function [duplicate]

Let's say we have two ifs that depend on each other: if var exists { if var is array { //Do stuff with var } else { //Resolve the problem } } else { //Resolve the ...
Mikayla Maki's user avatar
1vote
3answers
4kviews

Use unnamed object to invoke method or not?

If I have a class with only only public method. When I use this class, is it good to use unnamed object to invoke its method? normal: TaxFileParser tax_parser(tax_file_name); auto content = ...
Chen OT's user avatar
34votes
4answers
26kviews

Usage of magic strings/numbers [closed]

This is somewhat controversial topic, and I guess there is as many opinions as there are programmers. But for the sake of it, I want to know what are the common practices in business (or in your work ...
Daniel Gruszczyk's user avatar
43votes
12answers
4kviews

Coding style (do more, then simplify) [duplicate]

I'm a CS student and I have been coding for a few months shy of a year now, and I seem to have developed what I think may be a "bad" habit and I'm wondering if anyone does the same (or whether it's a ...
George Greg's user avatar
11votes
7answers
3kviews

Temporary variables vs line length requirements

I've been reading Martin Fowler's Refactoring. It is generally excellent but one of Fowler's recommendations seems to be causing a little trouble. Fowler recommends that you replace temporary ...
Kevin Burke's user avatar
0votes
2answers
735views

Question on refactoring and code design

Suppose, I have a class with a constant static final field. Then I want in certain situations that field to be different. It still can be final, because it should be initialized in constructor. My ...
dhblah's user avatar
  • 1,381

153050per page
close